package com.love.poetry.infrastructure.persist.security.impl;

import org.springframework.stereotype.Repository;

import com.love.poetry.domain.security.Role;
import com.love.poetry.infrastructure.persist.security.RoleRepository;
import com.youboy.core.orm.mybatis.MybatisRepositorySupport;

@Repository
public class MybatisRoleRepository extends
		MybatisRepositorySupport<String, Role> implements RoleRepository {

	@Override
	protected String getNamespace() {
		return "com.love.poetry.domain.security.Role";
	}

	@Override
	public void save(Role entity) {
		super.save(entity);
		if (entity.hasAuthority()) {
			getSqlSession().insert(getNamespace().concat(".saveAuthorities"),entity);
		}
	}

	@Override
	public void update(Role entity) {
		super.update(entity);
		getSqlSession().delete(getNamespace().concat(".deleteAuthorities"),entity);
		if (entity.hasAuthority()) {
			getSqlSession().insert(getNamespace().concat(".saveAuthorities"),entity);
		}
	}

}
